//
//  Hear_ProgressView.m
//  Hear
//
//  Created by mac on 2018/5/10.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "Hear_ProgressView.h"

@interface Hear_ProgressView()

@property (nonatomic, strong) UIView *tView;

@property (nonatomic, strong) UILabel *title;

@property (nonatomic, strong) UIView *bgview;

@end

@implementation Hear_ProgressView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    
    UIView *bgview = [UIView new];
    bgview.backgroundColor = [UIColor whiteColor];
    bgview.layer.cornerRadius = 5 * scaleWidth;
    bgview.layer.masksToBounds = YES;
    self.bgview = bgview;
    [self addSubview:bgview];
    
    [bgview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self);
        make.size.mas_equalTo(CGSizeMake(238 * scaleWidth, 105 * scaleHeight));
    }];
    
    UILabel *title = [UILabel new];
    title.font = [UIFont systemFontOfSize:12];
    title.textColor = [UIColor colorWithHexString:@"#2EC8FA"];
    title.textAlignment = NSTextAlignmentCenter;
    self.title = title;
    [bgview addSubview:title];
    
    UIView *borderView = [[UIView alloc] initWithFrame:CGRectMake(35 * scaleWidth, 42 * scaleHeight, 168 * scaleWidth, 10 * scaleHeight)];
    borderView.layer.cornerRadius = 5 * scaleWidth;
    borderView.layer.masksToBounds = YES;
    borderView.layer.borderColor = [UIColor colorWithHexString:@"#2EC8FA"].CGColor;
    borderView.layer.borderWidth = 1;
    [bgview addSubview:borderView];
    
    //进度
    UIView *tView = [[UIView alloc] init];
    tView.backgroundColor = [UIColor colorWithHexString:@"#2EC8FA"];
    tView.layer.cornerRadius = 5 * scaleWidth;
    tView.layer.masksToBounds = YES;
    self.tView = tView;
    [bgview addSubview:tView];
    
    UILabel *show = [UILabel new];
    show.text = @"合成中......";
    show.textColor = [UIColor colorWithHexString:@"#6E6E6E"];
    show.textAlignment = NSTextAlignmentCenter;
    [bgview addSubview:show];
    
    [show mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(bgview);
        make.top.mas_equalTo(borderView.mas_bottom).mas_offset(20 * scaleHeight);
    }];
}

- (void)setProgress:(CGFloat)progress {
    _progress = progress;

    _title.text = [NSString stringWithFormat:@"%.0f%%", ceilf(progress * 100)];

    _tView.frame = CGRectMake(35 * scaleWidth, 42 * scaleHeight, 168 * scaleWidth * progress, 10 * scaleHeight);
    
    _title.frame = CGRectMake(35 * scaleWidth + 168 * scaleWidth * progress, 21 * scaleHeight, 40 * scaleWidth, 9 * scaleHeight);
    _title.center = CGPointMake(35 * scaleWidth + 168 * scaleWidth * progress, 21 * scaleHeight);

}

@end
